package com.txhy.certificatechain.presenter.base;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: BasePresenter.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: MVP基类
 * 创建时间: 2018/9/19 15:36
 * 更新时间：2018/9/19 15:36
 * -----------------------------------------------------------------
 * 2018/9/19 15:36: 创建 BasePresenter.java (侯建军);
 * -----------------------------------------------------------------
 */
public abstract class BasePresenter<V> {
    protected Reference<V> mViewRef;
    public void attachView(V view){
        mViewRef = new WeakReference<V>(view);
    }
    protected V getView(){
        return mViewRef.get();
    }
    public boolean isViewAttached(){
        return mViewRef != null&&mViewRef.get()!=null;
    }
    public void detachView(){
        if(mViewRef!=null){
            mViewRef.clear();
            mViewRef = null;
        }
    }
}
